//
//  PTRequireOne.swift
//  PointTest28
//
//  Created by sc-chen on 2023/6/25.
//

import SwiftUI

struct PTRequireOne: View {
    @State var isShowingDetail = false
    @State var showingOptions = false
    
    var body: some View {
        List {
            ForEach(PTFuncRequireOne.allCases) { idcase in
                NavigationLink {
                    PTOneAnyDetail.init(funcOne: idcase)
                        .toolbar {
                            ToolbarItem(placement: .destructiveAction, content: {
                                Button(action: {
                                    showingOptions = true
                                }) {
                                    Image(systemName: "ellipsis")
                                }
                                .buttonStyle(.plain)
                            })
                        }
                        .confirmationDialog("", isPresented: $showingOptions) {
                            NavigationLink("详情", destination: PTFunDetailView(ptFunc: idcase))
                                .buttonStyle(.plain)
                            Button(action: {
                                showingOptions = false
                            }) {
                                Text("取消")
                            }
                        }
                } label: {
                    Text(idcase.label)
                        .padding(.top,10)
                        .padding(.bottom,10)
                }
            }
        }
    }
}

struct PTOneAnyDetail: View {
    let funcOne: PTFuncRequireOne
    var body: some View {
        switch funcOne {
        case .tel: PTDiaMobile()
        case .sms: PTSendMsg()
        case .mobileNet: PTMobileNetwork()
        case .wlan: PTWLAN()
        case .location: PTLocation()
        case .callRecord: PTCallRecording()
        case .localRecord: PTRecording()
        case .screenCaptureAndRecording: PTScreenShot()
        case .takePhotoAndVideo: PTCamera()
        case .receiveSMS: PTReceiveSms()
        case .contacts: PTReadContact()
        case .readCallLogs: PTCallRecords()
        case .readSMS: PTReadMsg()
        case .readMMS: PTReadMediaMsg()
        case .netBrowsingHistory: PTReadInternetContent()
        case .scheduleReading: PTReadSchedule()
        case .mediaAudio: PTReadVideo()
        case .biometrics: PTReadBiometrics()
        case .uuid: PTGetIMEI()
        case .apps: PTReadAllApp()
        case .bluetoothOn: PTOpenBluetooth()
        case .NFCOn: PTReadNFC()
        case .bluetoothPair: PTPairBluetooth()
        }
    }
}

struct PTRequireOne_Previews: PreviewProvider {
    static var previews: some View {
        PTRequireOne()
    }
}
